package no.somenvm.dreamplanners

import no.somenvm.dreamplanners.SkillHud.hud
import no.somenvm.dreamplanners.SkillUI.ui
import org.bukkit.Bukkit
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.command.CommandBody
import taboolib.common.platform.command.CommandHeader
import taboolib.common.platform.command.subCommand
import taboolib.common.platform.function.info
import taboolib.common.platform.function.submit
import taboolib.common.platform.function.submitAsync

@CommandHeader("plui", aliases = ["dplui","skillui"])
object Command {

    @CommandBody
    val open = subCommand {
        dynamic("player") {
            suggestion<ProxyCommandSender> { _, _ -> Bukkit.getOnlinePlayers().map { it.name } }

            execute<ProxyCommandSender> { _, _, argument ->
                val player = Bukkit.getPlayerExact(argument)!!
                SkillUI.updateSkillList(player)
                submit(async = true , delay = 1) {
                    ui.open(player)
                }
            }
        }
    }

    @CommandBody
    val reload = subCommand {
        execute<ProxyCommandSender> { sender, _, _ ->
            DreamPlanners.reload()
            sender.sendMessage("reload successful.")
        }
    }
}